class Solution:
    def countAndSay(self, n: int) -> str:

        # 双指针
        s = "1"
        for _ in range(n - 1):
            i = 0
            # 存储中间产生的字符串
            cur = []
            for j in range(len(s)):
                if s[j] != s[i]:
                    # 次数+这个数
                    c = str(j - i) + s[i]
                    i = j
                    cur.append(c)
            # 中间产生的字符串和 最后的合并
            s = "".join(cur) + str(len(s) - i) + s[-1]
        return s